import { Reducer, Effect } from 'umi';
import { getData } from '@/services/example'

export interface StateType {
  count?: number,
}

export interface ExampleModelType {
  namespace: string;
  state: StateType;
  effects: {
    fetchData: Effect;
  };
  reducers: {
    addCount: Reducer<StateType>;
  };
}

const Model: ExampleModelType = {
  namespace: 'example',
  state: {
    count: 0,
  },
  effects: {
    *fetchData(_, { call, put }) {
      const response = yield call(getData, 2000);
      console.log(response)
    },
  },
  reducers: {
    addCount(state, { payload }) {
      console.log({ payload })
      return {
        ...state,
        count: payload,
      }
    }
  },
}

export default Model;